package com.itheima.service.impl;

import com.itheima.mapper.UserMapper;
import com.itheima.pojo.User;
import com.itheima.queryParams.LoginInfoParam;
import com.itheima.service.LoginServise;
import com.itheima.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.HashMap;
import java.util.Objects;


@Service
public class LoginServiceImpl implements LoginServise {
    @Autowired
    private UserMapper userMapper;

    @Override
    public LoginInfoParam userLogin(User user) {
        User userInfo = userMapper.getUserLogin(user);
        if (!ObjectUtils.isEmpty(userInfo)){
            HashMap<String, Object> map = new HashMap<>();
            map.put("id",userInfo.getId());
            map.put("name",userInfo.getName());
            String token = JwtUtils.getJwt(map);
            return new LoginInfoParam(userInfo.getId(),userInfo.getName(),userInfo.getUsername(),token);
        }
        return null;
    }
}
